package com.example.administrator.yuejian23.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.administrator.yuejian23.Activity.AboutYuejianActivity;
import com.example.administrator.yuejian23.Bean.MyBean;
import com.example.administrator.yuejian23.Fragment.viewholder.MyViewHolder;
import com.example.administrator.yuejian23.R;
import com.squareup.picasso.Picasso;

/**
 * Created by Administrator on 2017/10/13.
 */

public class MyAdapter extends RecyclerView.Adapter {
    private ImageView textView_image;
    private Context context;
    private LayoutInflater layoutInflater;
    private MyBean myList;
    public MyAdapter(Context cxt,MyBean myList){
        this.context = cxt;
        this.myList=(MyBean)myList;
        layoutInflater =layoutInflater.from(cxt);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_myinfo,parent,false);
        MyViewHolder myViewHolder=new MyViewHolder(itemView);

        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        if (holder instanceof MyViewHolder){
            MyViewHolder myViewHolder= (MyViewHolder) holder;
            final MyBean myBean = myList;
            final String address="http://172.24.10.175/workout/Uploads/"+myBean.getPhoto();
            myViewHolder.textView_username.setText(myBean.getUser_name());
            Picasso.with(context)
                    .load(address)
                    .into(MyViewHolder.textView_Image);
            myViewHolder.button_yuejianabout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent=new Intent(view.getContext(), AboutYuejianActivity.class);
                    view.getContext().startActivity(intent);
                }
            });
        }

    }

    @Override
    public int getItemCount() {
        return myList==null?0:1;
    }
}
